package ex.hql.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ex.hql.mapper.MenuRoleMapper;
import ex.hql.pojo.MenuRole;
import ex.hql.pojo.RespBean;
import ex.hql.service.IMenuRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hql
 * @since 2021-08-19
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    /**
     * 更新角色菜单
     * @param rid
     * @param mids
     * @return
     */
    @Override
    @Transactional
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        MenuRoleMapper menuRoleMapper = getBaseMapper();
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if(mids==null||mids.length==0){
            return RespBean.success("更新成功！");
        }
        Integer record = menuRoleMapper.insertRecord(rid, mids);
        if(record==mids.length){
            return RespBean.success("更新成功！更新了"+record.toString()+"条信息！");
        }
        else {
           return RespBean.error("更新失败！");
        }
    }
}
